package com.iwhalecloud.uncc.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author zq
 * @date 2021/10/29 15:43
 * @description
 */
@Component
public class SendUtil {

    /**
     * 2 的 次方数
     */
    private static int oneSendMax;

    public static int getOneSendNum(int size){
        if(size < oneSendMax){
            return size;
        }else{
            return oneSendMax;
        }
    }

    public static int getSendTimes(int size){
        if(size < oneSendMax){
            return 1;
        }else{
            int i = size & (oneSendMax-1);
            if(i == 0){
                return size/oneSendMax;
            }else {
                return size/oneSendMax + 1;
            }

        }
    }

    @Value("${archiver.oneSendMax}")
    public void setOneSendMax(int oneSendMax) {
        SendUtil.oneSendMax = oneSendMax;
    }
}
